package com.cwh.taskcenter.domain.reward.model;

import com.alibaba.cola.domain.Entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author cwh
 */
@Entity
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class PointAccount {

    /**
     *
     */
    private Long id;

    /**
     * 用户id
     */
    private Long userId;

    /**
     * 总积分
     */
    private Long totalPoint;

    /**
     * 可用积分
     */
    private Long availablePoint;

    /**
     * 冻结积分
     */
    private Long frozenPoint;

    /**
     * 账户状态：0-禁用，1-正常
     */
    private Integer accStatus;

    /**
     * 创建时间
     */
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    private LocalDateTime updatedTime;

    public void addPoints(Long changePoint) {
        this.totalPoint += changePoint;
        this.availablePoint += changePoint;
    }

    public static PointAccount createNewAccount(Long userId) {
        return PointAccount.builder()
                .userId(userId)
                .totalPoint(0L)
                .availablePoint(0L)
                .frozenPoint(0L)
                .accStatus(1)
                .build();
    }
}
